/*
 * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
 *
 * https://www.mall4j.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */
package com.jf.cloud.user.controller.platform;

import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.user.dto.UserTravelsCommentDTO;
import com.jf.cloud.user.model.UserTravelsComment;
import com.jf.cloud.user.service.UserTravelsCommentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import ma.glasnost.orika.MapperFacade;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 
 *
 * @author zz
 * @date 2023-11-10 16:10:35
 */
@RestController("platformUserTravelsCommentController")
@RequestMapping("/p/user_travels_comment")
@Tag(name = "")
public class UserTravelsCommentController {

    @Autowired
    private UserTravelsCommentService userTravelsCommentService;

    @Autowired
    private MapperFacade mapperFacade;

    @GetMapping("/page")
    @Operation(summary = "获取列表", description = "分页获取列表")
    public ServerResponseEntity<PageVO<UserTravelsComment>> page(@Valid PageDTO pageDTO,@ParameterObject UserTravelsCommentDTO userTravelsCommentDTO) {
        PageVO<UserTravelsComment> userTravelsCommentPage = userTravelsCommentService.page(pageDTO,userTravelsCommentDTO);
        return ServerResponseEntity.success(userTravelsCommentPage);
    }

    @GetMapping
    @Operation(summary = "获取", description = "根据id获取")
    public ServerResponseEntity<UserTravelsComment> getById(@RequestParam Long id) {
        return ServerResponseEntity.success(userTravelsCommentService.getById(id));
    }

    @PostMapping
    @Operation(summary = "保存", description = "保存")
    public ServerResponseEntity<Void> save(@Valid @RequestBody UserTravelsCommentDTO userTravelsCommentDTO) {
        UserTravelsComment userTravelsComment = mapperFacade.map(userTravelsCommentDTO, UserTravelsComment.class);
        userTravelsComment.setId(null);
        userTravelsCommentService.save(userTravelsComment);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary = "更新", description = "更新")
    public ServerResponseEntity<Void> update(@Valid @RequestBody UserTravelsCommentDTO userTravelsCommentDTO) {
        UserTravelsComment userTravelsComment = mapperFacade.map(userTravelsCommentDTO, UserTravelsComment.class);
        userTravelsCommentService.update(userTravelsComment);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary = "删除", description = "根据id删除")
    public ServerResponseEntity<Void> delete(@RequestParam Long id) {
        userTravelsCommentService.deleteById(id);
        return ServerResponseEntity.success();
    }
}
